from django.db import models

from apps.api_tests.models import InterFaceCase
from utils.models import CoreModel, table_prefix, BaseModel
from apps.test_projects.models import TestProject


# Create your models here.

class TestScene(CoreModel):
    """测试业务流"""
    project = models.ForeignKey(
        to=TestProject, on_delete=models.PROTECT,
        help_text='所属项目', verbose_name='所属项目', db_comment='所属项目'
    )
    name = models.CharField(
        max_length=50,
        help_text='测试业务流名称', verbose_name='测试业务流名称', db_comment='测试业务流名称'
    )

    def __str__(self):
        return self.name

    class Meta:
        db_table = table_prefix + 'test_scene'
        db_table_comment = '测试业务流'

        verbose_name = "测试业务流"
        verbose_name_plural = verbose_name


class SceneToCase(BaseModel):
    icase = models.ForeignKey(
        to=InterFaceCase, on_delete=models.PROTECT,
        verbose_name='接口用例', help_text='接口用例', db_comment='接口用例',
    )
    scene = models.ForeignKey(
        to=TestScene, on_delete=models.PROTECT,
        verbose_name='测试业务流', help_text='测试业务流', db_comment='测试业务流'
    )
    sort = models.IntegerField(
        null=True, blank=True,
        verbose_name='执行顺序', help_text='执行顺序',
    )

    def __str__(self):
        return self.icase.title

    class Meta:
        db_table = table_prefix + 'scene_to_case'
        db_table_comment = '测试业务流中的执行步骤'

        verbose_name = '测试业务流中的执行步骤'
        verbose_name_plural = verbose_name
